import yaml
import os
from path.path import Path
import re
path=Path()
class Read_yaml:
    def __init__(self,file_name):
        self.name=file_name
    @property
    def read(self):
        if os.path.exists(os.path.join(path.root_path,'data/{}'.format(self.name))):
            with open(os.path.join(path.root_path,'data/{}'.format(self.name)),'r',encoding='utf-8') as f:
                self.yaml=yaml.safe_load(f)
            return self.yaml
        else:
            raise FileNotFoundError("{}文件不存在".format(self.name))

    @property
    def variable(self):
        if os.path.exists(os.path.join(path.root_path, '{}'.format(self.name))):
            with open(os.path.join(path.root_path, '{}'.format(self.name)), 'r', encoding='utf-8') as f:
                self.yaml = yaml.safe_load(f)
            return self.yaml
        else:
            raise FileNotFoundError("文件不存在")


